$('.select2').select2();
// $.get("header_menu.html",function(data){ $("#header").html(data); });
$.get("footer.html",function(data){ $("#footer").html(data); });

function pic_replace(dom1,dom2){
  var file = document.getElementById(dom1).files;
  var reader = new FileReader();
  reader.readAsDataURL(file[0]);
  reader.onload = function(e){
    var Img = '<img class="act_img_sty" src="'+this.result+'" width="85px" height="100px"/>';
    $('.'+dom2).html(Img)
  }
}
function GetQueryString(name)
{
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)return  unescape(r[2]); return null;
}

$(document).ready(function(){
    // $("#active").addClass("active");

  function getData(curr){
    $.ajax({
      type:"get",
      url:"http://114.116.72.220:9999/ActivityContent/",
      async:true,
      data:{
          activityId: GetQueryString('Index'),
      },
      success:function(data){
        dataView(data);
      }
    });

  }
  getData(1);
  function dataView(data){
      $('#activityName').val(data.activity_name);
      $('#activityNo').val(data.activity_no);
      $('#activityExplain').val(data.activity_content);
      $('#selectCity').val(data.activity_city);
      $('#datepicker').val(data.activity_time);
      $('.activity_pic').html(`<img src="${data.activity_pic}" class="act_img_sty" />`);

      $('#compereName').val(data.host[0].name);
      $('#compereExplain').val(data.host[0].introduce);
      $('.compere_pic').html(`<img src="${data.host[0].pic}"  class="act_img_sty" />`);

      $('#guest_box').html('');
      for (var i=0; i<data.guest.length; i++) {
        var guest = `<div class="col-lg-12">
                        <div class="col-lg-6 col-sm-12 itemList">
                           <div class="col-lg-12">
                              <span>嘉宾姓名</span>
                              <input readonly type="text" value="${data.guest[i].name}">
                            </div>
                           <div class="col-lg-12">
                                <span>嘉宾介绍</span>
                                <textarea readonly maxlength="130" class="form-control" rows="3" type="text" id="guestExplain" style="width: 80%;resize:none;vertical-align: top;">
                                    ${data.guest[i].introduce}
                                </textarea>
                            </div>
                          </div>
                          <div class="col-lg-6 col-sm-12 addImage">
                             <div class="col-lg-2 col-md-4">嘉宾照片</div>
                              <!--<input readonly onchange="pic_replace(\'guest_pic\',\'guest_pic\')" type="file" name="guestPic"/>-->
                              <label class="guest_pic col-lg-5 col-md-6" for="guest_pic">
                                <img src="${data.guest[i].pic}" class="act_img_sty" />
                              </label>
                          </div>
                        </div>`;
          $('#guest_box').append(guest);
      }
  }

});
